package com.example.demo.controller;

import com.example.demo.modal.Pattern;
import com.example.demo.service.PatternService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/pattern")
public class PatternController {
    @Autowired
    private PatternService PatternService;

    @GetMapping
    String action() {
        return "pattern";
    }

    @PostMapping(value = "/show")
    @ResponseBody
    public List<Pattern> show() {
        return PatternService.selectAll();
    }

    @PostMapping(value = "/update")
    @ResponseBody
    public String updat(@RequestBody Pattern  pattern){
        PatternService.updateByPrimaryKey(pattern);
        return "更改成功！"; }

    @PostMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam("id") int id){
        PatternService.deleteByPrimaryKey(id);
        return "删除成功！"; }

    @PostMapping("/save")
    @ResponseBody
    public String save(@RequestBody Pattern pattern){
        PatternService.save(pattern);
        return "保存成功！"; }


    @PostMapping("/max")
    @ResponseBody
    public int maxId(){
        return PatternService.selectMaxId();
    }


    @PostMapping("/find/rpId")
    @ResponseBody
    public List<Pattern> find_rpId(@RequestParam("rpId") int id){
        return PatternService.findByrpId(id);
    }

    @PostMapping("/find/rpName")
    @ResponseBody
    public List<Pattern> find_rpName(@RequestParam("rpName") String rpName){
        return PatternService.findByrpName(rpName);
    }

    @PostMapping("/find/rpRequir")
    @ResponseBody
    public List<Pattern> find_rpRequir(@RequestParam("rpRequir") String rpRequir){
        return PatternService.findByrpRequir(rpRequir);
    }

    @PostMapping("/find/rpConclu")
    @ResponseBody
    public List<Pattern> find_rpConclu(@RequestParam("rpConclu") String rpConclu){
        return PatternService.findByrpConclu(rpConclu);
    }

    @PostMapping("/find/rpRelationship")
    @ResponseBody
    public List<Pattern> find_rpRelationship(@RequestParam("rpRelationship") String rpRelationship){
        return PatternService.findByrpRelationship(rpRelationship);
    }

    @PostMapping("/find/rpConditions")
    @ResponseBody
    public List<Pattern> find_rpConditions(@RequestParam("rpConditions") String rpConditions){
        return PatternService.findByrpConditions(rpConditions);
    }

}
